//获取书籍信息
import axios from "axios";
import { ElMessage } from "element-plus";
import { ref } from "vue";
import { getCurrentInstance } from "vue";

export async function dianzan(target_id, proxy) {
  const formData = new FormData();
  formData.append("target_id", target_id);
  formData.append("type","book");
  console.log(formData);
  try {
    const response = await proxy.$http.post("/api/like/add", formData, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
    const res = response.data;
    console.log(res);
    const isSuccess = response.data.success;
    const message = response.data.message;
    if (isSuccess === false) {
      ElMessage.error(message);
    } else {
      // ElMessage.success("点赞书籍成功");
      return res;
    }
  } catch (error) {
    // console.error(`Error fetching ${book_id} books:`, error);
    return [];
  }
}

export async function dis_dianzan(target_id, proxy) {
  const formData = new FormData();
  formData.append("target_id", target_id);
  formData.append("type", "book");
  console.log(formData);
  try {
    const response = await proxy.$http.post("/api/like/cancel", formData, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
    const res = response.data.data;
    console.log(res);
    const isSuccess = response.data.success;
    const message = response.data.message;
    if (isSuccess === false) {
      ElMessage.error(message);
    } else {
      // ElMessage.success("书籍取消点赞成功");
      return res;
    }
  } catch (error) {
    // console.error(`Error fetching ${id} books:`, error);
    return [];
  }
}
